package com.azt.utils;

import org.apache.poi.ss.formula.functions.T;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 自己的String处理工具类
 *
 * @author 张栋  2016年7月22日下午1:16:47
 */
public class MyCollectionUtils {


    /**
     * 深度复制
     * http://blog.csdn.net/lian_1988/article/details/45970927
     * Created by 张栋 on 2017/3/22 10:12
     */
    public static <T> List<T> deepCopy(List<T> src) throws IOException, ClassNotFoundException {

        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(byteOut);
        out.writeObject(src);
        ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
        ObjectInputStream in = new ObjectInputStream(byteIn);
        List<T> dest = (List<T>) in.readObject();
        return dest;
    }

    /**
     * 复制对象
     * Created by 张栋 on 2017/3/22 10:27
     */
    public static <T> T deepCopy(T obj) throws IOException, ClassNotFoundException{
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(bos);
        oos.writeObject(obj);
        ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()));
        return (T) ois.readObject();
    }


}
